package com.example.qiniutest.aop.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.qiniutest.aop.entity.Student;
import com.example.qiniutest.aop.entity.Test;
import com.example.qiniutest.aop.service.TestService;
import com.example.qiniutest.aop.vo.TestVo;
import com.example.qiniutest.util.R;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: qiniuTest
 * @description:
 * @author: xpp011
 * @create: 2021-10-27 13:18
 **/

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    TestService testService;

    @PostMapping("/insert")
    public R insert(@RequestBody TestVo testVo){
        Test test=new Test();
        BeanUtils.copyProperties(testVo,test);
        return R.status(testService.save(test));
    }

    @DeleteMapping("/remove")
    public R remove(@RequestParam List<Long> ids){
        return R.status(testService.removeByIds(ids));
    }

    @GetMapping("/page")
    public R list(Page<Test> page){
        IPage<Test> studentIPage = testService.getBaseMapper().selectPage(page, null);
        return R.data(studentIPage);
    }
}
